import http from "@/common/http";
import {Order, OrderReturnReason, ReturnApply} from "@/common/interfaces/order";
import orderListResponse from "@/apis/mock/order.json";
import returnApplyResponse from '@/apis/mock/returnApply.json'
import reasonResponse from '@/apis/mock/reason.json'
import orderSetting from '@/apis/mock/orderSetting.json'

export async function queryOrderList(params?: any, useMock?: boolean) {
  if (useMock) {
    return Promise.resolve(orderListResponse)
  }
  return http('/api/order/order/list', {
    method: 'POST',
    data: {
      ...params,
    },
  });
}

export async function removeOrder(params: { ids: number[] }) {
  return http('/api/order/order/delete', {
    method: 'POST',
    data: {
      ...params,
    },
  });
}


export async function updateOrder(params: Order) {
  return http('/api/order/order/update', {
    method: 'POST',
    data: {
      ...params,
    },
  });
}

export async function queryReturnApply(params?: any, useMock?: boolean) {
  if (useMock) {
    return Promise.resolve(returnApplyResponse)
  }
  return http({
    url: '/api/order/returnapply/list',
    method: 'GET',
    params
  });
}

export async function removeReturnApply(data: number[]) {
  return http('/api/order/returnapply/delete', {
    method: 'POST',
    data
  });
}

export async function updateReturnApply(params: ReturnApply) {
  return http('/api/order/returnapply/update', {
    method: 'POST',
    data: {
      ...params,
    },
  });
}

export async function queryReturnReasonList(params?: any, useMock?: boolean) {
  if (useMock) {
    return Promise.resolve(reasonResponse)
  }
  return http({
    url: '/api/order/returnreason/list',
    method: 'GET',
    params
  });
}

export async function removeReturnReason(data: number[]) {
  return http('/api/order/returnreason/delete', {
    method: 'POST',
    data
  });
}

export async function addReturnReason(data: OrderReturnReason) {
  return http('/api/order/returnreason/add', {
    method: 'POST',
    data
  });
}

export async function updateReturnReason(params: OrderReturnReason) {
  return http('/api/order/returnreason/update', {
    method: 'POST',
    data: {
      ...params,
    },
  });
}

export async function queryOrderSetting(params?: any, useMock?: boolean) {
  if (useMock) {
    return Promise.resolve(orderSetting)
  }
  return http({
    url: '/api/order/setting/list',
    method: 'POST',
    params
  });
}

export async function removeSetting(params: { ids: number[] }) {
  return http('/api/order/setting/delete', {
    method: 'POST',
    data: {
      ...params,
    },
  });
}

export async function addSetting(params: any) {
  return http('/api/order/setting/add', {
    method: 'POST',
    data: {
      ...params,
    },
  });
}

export async function updateSetting(params: any) {
  return http('/api/order/setting/update', {
    method: 'POST',
    data: {
      ...params,
    },
  });
}
